# -*- coding: utf-8 -*-
"""
TG分割器布局组件 - TgSplitterLayout, TgHorizontalLayout, TgVerticalLayout
分割器布局组件和水平/垂直布局组件
"""
from PySide6.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QSplitter
from PySide6.QtCore import Qt
from .hbox_layout import TgHBoxLayout
from .vbox_layout import TgVBoxLayout
from ..base import TgBaseWidget


class TgHorizontalLayout(TgHBoxLayout):
    """TG水平布局容器(基于QWidget)"""
    
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setContentsMargins(0, 0, 0, 0)
        self.setSpacing(0)


class TgVerticalLayout(TgVBoxLayout):
    """TG垂直布局容器(基于QWidget)"""
    
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setContentsMargins(0, 0, 0, 0)
        self.setSpacing(0)


class TgSplitterLayout(TgBaseWidget):
    """TG分割器布局组件"""
    
    def __init__(self, orientation=Qt.Orientation.Horizontal, parent=None):
        self.orientation = orientation
        # 初始化TG组件属性
        self._component_name = self.__class__.__name__
        self._is_initialized = False
        self._style_applied = False
        self._theme = 'default'
        self._size_hint = 'medium'
        
        # 先初始化QWidget
        QWidget.__init__(self, parent)
        
        # 手动调用初始化
        self.initialize()
    
    def setup_ui(self):
        """设置用户界面"""
        self._layout = QHBoxLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)
        self._layout.setSpacing(0)
        
        self.splitter = QSplitter(self.orientation)
        self._layout.addWidget(self.splitter)
    
    def apply_style(self):
        """应用样式"""
        # 分割器布局的样式通过子组件来实现
        self._style_applied = True
    
    def add_widget(self, widget):
        """添加子部件"""
        self.splitter.addWidget(widget)
    
    def set_sizes(self, sizes):
        """设置分割器尺寸"""
        self.splitter.setSizes(sizes)
    
    def set_children_collapsible(self, collapsible):
        """设置子部件是否可折叠"""
        self.splitter.setChildrenCollapsible(collapsible)
    
    def set_margins(self, left, top, right, bottom):
        """设置边距"""
        self._layout.setContentsMargins(left, top, right, bottom)
    
    def set_spacing(self, spacing):
        """设置间距"""
        self._layout.setSpacing(spacing) 